(function(){
	var Page = {
		init:function(){
			this.render();
			this.event();
		},
		//绑定事件
		event:function(){
			$(".btnlogin").click(function(){
				var mobile=$(".mobile").val()
				var code=$(".code").val()
				if(mobile==""){alert("请输入手机号");return}
				if(code==""){alert("请输入验证码");return}
				$.ajax({
					url:'http://39.106.145.173:8089/leveling/login',
				
					// url:'http://192.168.1.109:8089/leveling/login',
					type:'POST',
					async:true,
					data:{
						mobile:mobile,
						code:code
					},
					dataType: "json",
					success: function(data){
						if(data.code === 200 ){
							var user=JSON.stringify(data.t); 
							sessionStorage.setItem("backUserInfo", user);
							setCookie('uid',user.id);
							setCookie('sdktoken',user.imToken);
							window.location.href ='PowerLevelweb/html/PowerLevel/Information.html';
						}else{
							alert(data.msg)	
						}
					}
				 });
			})
			$(".btncode").click(function(){
			   	var mobile=$(".mobile").val();
				var tel_zz = /^1(3|4|5|7|8)\d{9}$/;
				if(mobile==""){alert("请输入手机号");return}else if(!tel_zz.test(mobile)){alert('手机格式错误！');return false;}
				$.ajax({
					url:'http://39.106.145.173:8089/leveling/sendMobileCode',
					type:'POST',
					async:true,
					data:{
						mobile:mobile,
						type:"login"
					},
					dataType: "json",
					success: function(data){
						if(data.code === 200 ){
							alert("发送验证码成功");
							var wait=60;  
							function time() {  
									if (wait == 0) {            
										$(this).val("发送验证码");  
										wait = 60;  
									} else {   
										$(this).val("重新发送(" + wait + "s)");
										wait--;  
										setTimeout(function() {  
											time()  
										},  
										1000)  
									}  
								};
						   time();
						}else{
							alert(data.msg)	
						}
					}
				 });
			})
		},
		//渲染页面
		render:function(){
		}
	};
	Page.init();
})();